/*    */ package org.jeecgframework.p3.cg.def;
/*    */ 
/*    */ import freemarker.template.Configuration;
/*    */ import freemarker.template.Template;
/*    */ import freemarker.template.TemplateException;
/*    */ import java.io.File;
/*    */ import java.io.FileOutputStream;
/*    */ import java.io.IOException;
/*    */ import java.io.OutputStreamWriter;
/*    */ import java.io.PrintStream;
/*    */ import java.io.Writer;
/*    */ import java.util.Map;
/*    */ import org.apache.commons.logging.Log;
/*    */ import org.apache.commons.logging.LogFactory;
/*    */ 
/*    */ public class FreemarkerEngine
/*    */ {
/* 18 */   private static final Log log = LogFactory.getLog(FreemarkerEngine.class);
/*    */   
/*    */   public static void createFileByFTL(Configuration cfg, Map<String, Object> root, String ftlName, String fileDirPath, String targetFile)
/*    */   {
/* 22 */     String encoding = CodeResourceUtil.getSYSTEM_ENCODING();
/* 23 */     String workspasePath = CodeResourceUtil.getConfigInfo("workspace_path");
/* 24 */     boolean isReplace = new Boolean(CodeResourceUtil.getConfigInfo("isReplace")).booleanValue();
/*    */     try
/*    */     {
/* 27 */       Template temp = cfg.getTemplate(ftlName, encoding);
/* 28 */       File file = new File(workspasePath + File.separator + fileDirPath + File.separator + targetFile);
/* 29 */       if (!file.exists()) {
/* 30 */         new File(file.getParent()).mkdirs();
/* 31 */         System.out.println("创建文件:" + file.getAbsolutePath());
/*    */       }
/* 33 */       else if (isReplace) {
/* 34 */         System.out.println("替换文件:" + file.getAbsolutePath());
/*    */       }
/*    */       
/*    */ 
/* 38 */       FileOutputStream os = new FileOutputStream(file);
/* 39 */       Writer out = new OutputStreamWriter(os, encoding);
/* 40 */       temp.process(root, out);
/* 41 */       out.flush();
/*    */     } catch (IOException e) {
/* 43 */       e.printStackTrace();
/*    */     } catch (TemplateException e) {
/* 45 */       e.printStackTrace();
/*    */     }
/*    */   }
/*    */ }


/* Location:              /Users/guo/.m2/repository/org/jeewxframework/P3-Codegenerate/2.0.1/P3-Codegenerate-2.0.1.jar!/org/jeecgframework/p3/cg/def/FreemarkerEngine.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */